package com.etc.springbootssm.job;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * public abstract class QuartzJobBean implements Job
 */
@Component
public class MyJob extends QuartzJobBean {

    @Autowired
    private JavaMailSender mailSender;


    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {

        //具体要做的事情，我们后面修改为调用其他方法
        System.out.println("MyJob executeInternal :" + new Date());

        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        //设置simpleMailMessage的属性
        simpleMailMessage.setSubject("主题信息"+new Date());
        simpleMailMessage.setFrom("2511277093@qq.com");
        ArrayList<String> list = new ArrayList<>();
        list.add("1968802445");
        list.add("1873946090");
        list.add("2960497603");
        list.add("1317868838");
        for (String qq : list) {
            simpleMailMessage.setTo(qq+"@qq.com");
            simpleMailMessage.setText("http://n.sinaimg.cn/front/243/w642h401/20190325/vfIm-hutwezf3463525.png");
            mailSender.send(simpleMailMessage);
            System.out.println("发送成功!");
        }
    }
}

